Fixed Stripe Service coming up if billing portal manager errors#27468
Fixed Stripe Service coming up if billing portal manager errors#27468
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughError handling in 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js (1)
188-189: Strengthen this regression test with call assertions.On Line 188-Line 189, this validates only the return value. Add API interaction assertions to lock behavior (update attempted, no fallback create).
Suggested test diff
const result = await manager.createOrUpdateConfiguration('bpc_existing'); assert.equal(result, 'bpc_existing'); + sinon.assert.calledOnce(mockApi.updateBillingPortalConfiguration); + sinon.assert.notCalled(mockApi.createBillingPortalConfiguration);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js` around lines 188 - 189, The test only asserts the return value of manager.createOrUpdateConfiguration('bpc_existing'); add assertions that the billing-portal configuration update API was invoked and that the create API was not called: e.g., assert that the stub/spy for the billing portal configurations.update method was called once with an object containing id 'bpc_existing' (or the expected params) and assert that the configurations.create stub/spy was not called; use the existing sinon/sandbox stubs used in this test file to check calls on the billing portal client so the test locks behavior to "update attempted, no fallback create."
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ghost/core/core/server/services/stripe/billing-portal-manager.js`:
- Around line 95-96: The catch-all that returns id on any error (except
resource_missing) hides real Stripe/API failures; update the try/catch around
the billing portal config modification in billing-portal-manager.js to log the
full Stripe error (error.type, error.code, error.message, and stack) using the
module's logger, and only swallow the error when it exactly matches the
confirmed "default config" signature (compare error.code/type/message
explicitly); rethrow or surface any other unexpected errors and add a
breadcrumb/monitoring event so startup failures are alerted.
---
Nitpick comments:
In `@ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js`:
- Around line 188-189: The test only asserts the return value of
manager.createOrUpdateConfiguration('bpc_existing'); add assertions that the
billing-portal configuration update API was invoked and that the create API was
not called: e.g., assert that the stub/spy for the billing portal
configurations.update method was called once with an object containing id
'bpc_existing' (or the expected params) and assert that the
configurations.create stub/spy was not called; use the existing sinon/sandbox
stubs used in this test file to check calls on the billing portal client so the
test locks behavior to "update attempted, no fallback create."
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1af96786-0891-4b45-a46c-35c77adce480
📒 Files selected for processing (2)
ghost/core/core/server/services/stripe/billing-portal-manager.jsghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js
d57953b to
ce6d110
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js (1)
176-190: Strengthen this regression test with interaction assertionsLine 188-Line 189 validates the returned ID, but this can still pass if the update path is skipped or create fallback is used accidentally. Add explicit call assertions to lock the intended branch behavior.
Proposed test hardening
it('returns the passed id when failing with a non-resource based error', async function () { mockSettingsCache.get.withArgs('title').returns('Test Site'); const genericError = new Error('Stripe API error'); mockApi.updateBillingPortalConfiguration.rejects(genericError); const manager = new BillingPortalManager({ api: mockApi, models: {Settings: mockSettingsModel}, settingsCache: mockSettingsCache }); manager.configure({siteUrl: 'https://example.com'}); const result = await manager.createOrUpdateConfiguration('bpc_existing'); assert.equal(result, 'bpc_existing'); + sinon.assert.calledOnce(mockApi.updateBillingPortalConfiguration); + sinon.assert.notCalled(mockApi.createBillingPortalConfiguration); + assert.equal(mockApi.updateBillingPortalConfiguration.firstCall.args[0], 'bpc_existing'); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js` around lines 176 - 190, The test must assert the API interactions to ensure the update path was exercised; after calling BillingPortalManager.createOrUpdateConfiguration('bpc_existing') add assertions that mockApi.updateBillingPortalConfiguration was called once with the existing id (and expected payload) and that mockApi.createBillingPortalConfiguration was not called. Locate the test using BillingPortalManager and the createOrUpdateConfiguration invocation and add these call assertions (e.g. sinon/assert-style checks) referencing mockApi.updateBillingPortalConfiguration and mockApi.createBillingPortalConfiguration to lock the intended branch behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js`:
- Around line 176-190: The test must assert the API interactions to ensure the
update path was exercised; after calling
BillingPortalManager.createOrUpdateConfiguration('bpc_existing') add assertions
that mockApi.updateBillingPortalConfiguration was called once with the existing
id (and expected payload) and that mockApi.createBillingPortalConfiguration was
not called. Locate the test using BillingPortalManager and the
createOrUpdateConfiguration invocation and add these call assertions (e.g.
sinon/assert-style checks) referencing mockApi.updateBillingPortalConfiguration
and mockApi.createBillingPortalConfiguration to lock the intended branch
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 626c5ab4-c3a9-4389-87aa-5b2ee82fecb8
📒 Files selected for processing (2)
ghost/core/core/server/services/stripe/billing-portal-manager.jsghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
- ghost/core/core/server/services/stripe/billing-portal-manager.js
ref ONC-1656 Prevents the whole Stripe Service from erroring if the billing portal manager encounters an error while trying to update the billing portal configuration. This can happen if the billing portal configuration that Ghost has created has been made the default one by the Stripe Account owner.
6382e68 to
30720f0
Compare
|
E2E Tests FailedTo view the Playwright test report locally, run: REPORT_DIR=$(mktemp -d) && gh run download 24673507120 -n playwright-report -D "$REPORT_DIR" && npx playwright show-report "$REPORT_DIR" |
2 similar comments
E2E Tests FailedTo view the Playwright test report locally, run: REPORT_DIR=$(mktemp -d) && gh run download 24673507120 -n playwright-report -D "$REPORT_DIR" && npx playwright show-report "$REPORT_DIR" |
E2E Tests FailedTo view the Playwright test report locally, run: REPORT_DIR=$(mktemp -d) && gh run download 24673507120 -n playwright-report -D "$REPORT_DIR" && npx playwright show-report "$REPORT_DIR" |
| } | ||
| throw err; | ||
|
|
||
| logging.error('Failed to update the billing portal configuration', { |
There was a problem hiding this comment.
nitpick: if we wanted to monitor those logs, it might be useful to have some further information in them, so we could action on it.
There was a problem hiding this comment.
I think the error itself should help! That will have a message w plenty of context



ref ONC-1656
Prevents the whole Stripe Service from erroring if the billing portal manager encounters an error while trying to update the billing portal configuration. This can happen if the billing portal configuration that Ghost has created has been made the default one by the Stripe Account owner.